package com.pengtu.service.project;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.pengtu.dao.project.SubentryDao;
import com.pengtu.dao.project.SubprojectDao;
import com.pengtu.dao.project.SubunitDao;
import com.pengtu.entity.project.SubentryInfo;
import com.pengtu.entity.project.SubprojectInfo;
import com.pengtu.entity.project.SubunitInfo;

@Component
@Transactional
public class SubManager {

	private SubprojectDao subprojectDao;
	private SubunitDao subunitDao;
	private SubentryDao subentryDao;
	/**
	 * 
	 * @param string
	 * @param id
	 * @return
	 * 根据属性值查找出符合条件的一组对象
	 */
	//操做合同子单位对象
	@Transactional(readOnly=true)
	public List<SubunitInfo> findBySubunit(String propertyName, String value) {
		// TODO Auto-generated method stub
		return subunitDao.findBy(propertyName, value);
	}
	@Transactional(readOnly=true)
	public SubunitInfo getSubunit(String propertyName, String value) {
		if(propertyName.equalsIgnoreCase("id"))return subunitDao.get(value);
		return subunitDao.findUniqueBy(propertyName, value);
	}
	
	/**
	 * 
	 * saveSubunit:
	 * 适用:保存子单位工程对象
	 * @param subunit 
	 * @exception 
	 * @since  1.0.0
	 */
	public void saveSubunit(SubunitInfo subunit) {
		// TODO Auto-generated method stub
		subunitDao.save(subunit);
	}
	/***
	 * 
	 * deteleSubunit:
	 * 适用:根据Id删除子单位信息
	 * @param id 
	 * @exception 
	 * @since  1.0.0
	 */
	public void deteleSubunit(String id) {
		// TODO Auto-generated method stub
		subunitDao.delete(id);
	}

	//操作分部工程
	@Transactional(readOnly=true)
	public List<SubprojectInfo> findBySubproject(String propertyName, String value) {
		// TODO Auto-generated method stub
		return subprojectDao.findBy(propertyName, value);
	}
	
	@Transactional(readOnly=true)
	public SubprojectInfo getSubproject(String propertyName, String value) {
		if(propertyName.equalsIgnoreCase("id"))return subprojectDao.get(value);
		return subprojectDao.findUniqueBy(propertyName, value);
	}
	
	public void saveSubProject(SubprojectInfo subproject) {
		// TODO Auto-generated method stub
		subprojectDao.save(subproject);
	}
	/**
	 * 根据id删除子分部信息
	 * deleteSubproject:
	 * 适用:
	 * @param id 
	 * @exception 
	 * @since  1.0.0
	 */
	public void deleteSubproject(String id) {
		 	 subprojectDao.delete(id);
	}
	
	
	//操作分项工程
	@Transactional(readOnly=true)
	public List<SubentryInfo> findBySubentryInfo(String propertyName, String value) {
		// TODO Auto-generated method stub
		return subentryDao.findBy(propertyName, value);
	}
	@Transactional(readOnly=true)
	public SubentryInfo getSubentry(String propertyName, String value) {
		if(propertyName.equalsIgnoreCase("id"))return subentryDao.get(value);
		return subentryDao.findUniqueBy(propertyName, value);
	}
	
	public void saveSubentry(SubentryInfo subentry) {
		// TODO Auto-generated method stub
		subentryDao.save(subentry);
	}
	/**
	 * 
	 * deleteSubentry:
	 * 适用:删除分项
	 * @param id 
	 * @exception 
	 * @since  1.0.0
	 */
	public void deleteSubentry(String id) {
		subentryDao.delete(id);
	}
	
	
	
	@Autowired
	public void setSubprojectDao(SubprojectDao subprojectDao) {
		this.subprojectDao = subprojectDao;
	}
	@Autowired
	public void setSubunitDao(SubunitDao subunitDao) {
		this.subunitDao = subunitDao;
	}

	@Autowired
	public void setSubentryDao(SubentryDao subentryDao) {
		this.subentryDao = subentryDao;
	}

}
